package com.security.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * 认证服务器配置
 */
@Configuration
@EnableWebSecurity
public class WebSecurityServer extends WebSecurityConfigurerAdapter {

    /**
     * 认证配置 （登录和访问配置）
     * @param http
     * @throws Exception
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/oauth/**","login/**","logout/**").permitAll()
                .anyRequest().authenticated() //剩下的需要认证
                .and().formLogin().permitAll()
                ;
    http.csrf().disable();
    }

    @Bean
    public AuthenticationManager getAuthenticationManager() throws Exception {
        return super.authenticationManager();
    }
}
